################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Analysis Tax and Benefit System
#Table B 2
#
#Verena Fetscher
#July 2022
####################

####################
# Load packages
####################

library(tidyverse)
library(xtable)

####################
# Load data
####################

load("DataFile_07_Replacement.Rda")
load("replacement.Rda")


##########################
#Illustrations: Married couple
##########################

replacement%>%
  filter(famtype=="married") %>%
  group_by(Country) %>%
  summarise(RR_100 = mean(RR[AW==100],na.rm=T),
            RR_50 = mean(RR[AW==50],na.rm=T),
            RR_200 = mean(RR[AW==200],na.rm=T)) -> df


min<-rbind(min(df$RR_50),min(df$RR_100),min(df$RR_200))
mean<-rbind(mean(df$RR_50),mean(df$RR_100),mean(df$RR_200))
max<-rbind(max(df$RR_50),max(df$RR_100),max(df$RR_200))

df_table<-cbind(min,mean,max)
rownames(df_table)<-c("AW 50%", "AW 100%", "AW 200%")
colnames(df_table)<-c("min", "mean", "max")


##########################
#Produces Table B.2: Married couple, 2 children, gross earning spouse 67% of AW.
##########################
xtable(df_table, caption="Married couple, 2 children, gross earning spouse 67% of AW")


